;; 关闭工具栏
(tool-bar-mode -1)

;; 关闭滚动栏
(scroll-bar-mode -1)

;; 关闭菜单栏
;;(menu-bar-mode -1)

;; 关闭启动画面
(setq inhibit-startup-screen t)

(setq package-enable-at-startup nil)

;; 设置系统编码
;; UTF-8 as default encoding
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8-unix)

;; I don't like the bell ring
(setq ring-bell-function #'ignore
      visible-bell nil)

;; blink the cursor
(blink-cursor-mode 1)

(global-hl-line-mode 1)

;; 高亮当前行，使用浅灰色背景条
;;(set-face-background hl-line-face "#F2F2F2")

;; 设定垃圾回收阈值，加速启动速度
(setq gc-cons-threshold most-positive-fixnum)

;; 字体大小 12pt 
(set-face-attribute 'default nil :height 100)

;; 设置英文字体
;;(add-to-list 'default-frame-alist '(font . "JetBrains Mono-14"))

;; set default font
(set-frame-font
 (cond
  ((string-equal system-type "windows-nt")
   (if (member "JetBrains Mono" (font-family-list)) "JetBrains Mono-14" nil ))
  ((string-equal system-type "darwin")
   (if (member "Menlo" (font-family-list)) "Menlo-16" nil ))
  ((string-equal system-type "gnu/linux")
   (if (member "DejaVu Sans Mono" (font-family-list)) "DejaVu Sans Mono" nil ))
  (t nil))
 t t)

;; set font for emoji
(set-fontset-font
 t
 '(#x1f300 . #x1fad0)
 (cond
  ((member "Noto Color Emoji" (font-family-list)) "Noto Color Emoji")
  ((member "Noto Emoji" (font-family-list)) "Noto Emoji")
  ((member "Segoe UI Emoji" (font-family-list)) "Segoe UI Emoji")
  ((member "Symbola" (font-family-list)) "Symbola")
  ((member "Apple Color Emoji" (font-family-list)) "Apple Color Emoji"))
 ;; Apple Color Emoji should be before Symbola, but Richard Stallman skum disabled it.
 ;; GNU Emacs Removes Color Emoji Support on the Mac
 ;; http://ergoemacs.org/misc/emacs_macos_emoji.html
 ;;
 )

;; 设置中文字体
;; http://ergoemacs.org/emacs/emacs_make_modern.html
(set-fontset-font
 t
 '(#x4e00 . #x9fff)
 (cond
  ((string-equal system-type "windows-nt")
   (cond
    ((member "Microsoft YaHei" (font-family-list)) "Microsoft YaHei")
    ((member "Microsoft JhengHei" (font-family-list)) "Microsoft JhengHei")
    ((member "SimHei" (font-family-list)) "SimHei")))
  ((string-equal system-type "darwin")
   (cond
    ((member "Hei" (font-family-list)) "Hei")
    ((member "Heiti SC" (font-family-list)) "Heiti SC")
    ((member "Heiti TC" (font-family-list)) "Heiti TC")))
  ((string-equal system-type "gnu/linux")
   (cond
    ((member "WenQuanYi Micro Hei" (font-family-list)) "WenQuanYi Micro Hei")))))


;; backup and file related
;; http://ergoemacs.org/emacs/emacs_make_modern.html
(defun xah-save-all-unsaved ()
  "Save all unsaved files. no ask.
Version 2019-11-05"
  (interactive)
  (save-some-buffers t ))

(if (version< emacs-version "27")
    (add-hook 'focus-out-hook 'xah-save-all-unsaved)
  (setq after-focus-change-function 'xah-save-all-unsaved))

(setq make-backup-files nil)
(setq backup-by-copying t)
(setq create-lockfiles nil)
(setq auto-save-default nil)


;; indentation, end of line

(electric-indent-mode 0)

(set-default 'tab-always-indent 'complete)

;; no mixed tab space
(setq-default indent-tabs-mode nil)
									   
;; 4 is more popular than 8.
(setq-default tab-width 4)

(setq sentence-end-double-space nil )

;; buffer 
(setq save-interprogram-paste-before-kill t)
(global-auto-revert-mode 1)
(setq auto-revert-verbose nil)
(global-set-key (kbd "<f5>") 'revert-buffer)

;; 
;;(speedbar 1)

;; 调节窗口透明度
(set-frame-parameter (selected-frame) 'alpha '(85 . 50))
(add-to-list 'default-frame-alist '(alpha . (85 . 50)))

(if (display-graphic-p)
    (setq initial-frame-alist
          '(
            (tool-bar-lines . 0)
            ;;(background-color . "honeydew")
            (width . 106)
            (height . 56)
            ))
  (setq initial-frame-alist '( (tool-bar-lines . 0))))

(setq default-frame-alist
      '(
        (tool-bar-lines . 0)
        (width . 100)
        (height . 55)))

(provide 'init-startup)

